import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['KaiTi']  # 指定默认字体
plt.rcParams['axes.unicode_minus'] = False  # 解决保存图像是负号'-'显示为方块的问题

raw_data = {'水果': ['香蕉', '苹果', '草莓'],
            '价格': [2, 4, 10],
            '数量': [5, 3, 6], }
df = pd.DataFrame(raw_data)

pos = list(range(len(df['水果'])))
width = 0.3
plt.bar([p - width / 2 for p in pos], df['价格'], width, color='#FFCCCC', label=df['水果'][0])
plt.bar([p + width / 2 for p in pos], df['数量'], width, color='#6699CC', label=df['水果'][1])
plt.xticks(np.linspace(0, 2, 3), df['水果'])
plt.legend(['价格', '数量'], loc='upper left')
plt.show()
